package edu.ped.android.view;

import java.util.Observable;
import java.util.Observer;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import edu.ped.android.layout.NumberPicker;

public class MyNumberPicker extends NumberPicker {

	Observable obs = new Observable() {

		@Override
		protected void setChanged() {
			super.setChanged();
		}
		public void notifyObservers() {
			setChanged();
			super.notifyObservers();
		};
	};
	
	public MyNumberPicker(Context context, AttributeSet attributeSet) {
		super(context, attributeSet);
	}

	
	@Override
	public void increment() {
		super.increment();
		if(value <= 0)
			setValue(1);
		obs.notifyObservers();
	}

	@Override
	public void decrement() {
		super.decrement();
		if(value <= 0)
			setValue(1);
		obs.notifyObservers();
	}

	@Override
	public void setValue(int value) {
		if(value <= 0)
			setValue(1);
		super.setValue(value);
		Log.i("PED","setvalue !");
		obs.notifyObservers();
	}
	
	public void addObserver(Observer observer){
		obs.addObserver(observer);
	}
	
	public Observable getObservable(){
		return obs;
	}
}
